package com.keyinong.parkin.home.adapter;

import java.util.ArrayList;

import com.example.parkin.R;
import com.keyinong.parkin.home.bean.MeetingRoomBean;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;

public class HuTImeAdapter extends BaseAdapter {
      Context context;
      ArrayList<MeetingRoomBean> list;
      String min_lenght;
      
      
	public HuTImeAdapter(Context context, ArrayList<MeetingRoomBean> list,String min_lenght) {
		super();
		this.context = context;
		this.list = list;
		this.min_lenght=min_lenght;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View view, ViewGroup parent) {
		ViewHanlde handle;
		
		if (view == null) {
			handle = new ViewHanlde();
			if(min_lenght.equals("5") || min_lenght.equals("4")){
				handle = new ViewHanlde();
				view = LayoutInflater.from(context).inflate(
						R.layout.item_grid_daytime, null);
				handle.tv_hsstart = (TextView) view
						.findViewById(R.id.tv_hsstart);
				handle.tv_hsto = (ImageView) view
						.findViewById(R.id.tv_hsto);
				handle.tv_hsend = (TextView) view
						.findViewById(R.id.tv_hsend);
				view.setTag(handle);
			}
			else{
				view = LayoutInflater.from(context).inflate(
						R.layout.item_grid_hstime, null);
				handle.tv_hsstart = (TextView) view
						.findViewById(R.id.tv_hsstart);
				handle.tv_hsto = (ImageView) view
						.findViewById(R.id.tv_hsto);
				handle.tv_hsend = (TextView) view
						.findViewById(R.id.tv_hsend);
				view.setTag(handle);	
			}
			
		}else{
			handle=(ViewHanlde) view.getTag();
		}
		handle.tv_hsstart.setText(list.get(position).getStart_hour());
		handle.tv_hsend.setText(list.get(position).getEnd_hour());
		
		if(list.get(position).getInselect()==0);
		{
			view.setBackgroundColor(context.getResources().getColor(R.color.white_1));
			handle.tv_hsstart.setTextColor(context.getResources().getColor(R.color.timeGray));
//			handle.tv_hsto.setBackgroundResource(R.drawable.img_time_togray);
			handle.tv_hsto.setImageResource(R.drawable.img_time_togray);
			handle.tv_hsend.setTextColor(context.getResources().getColor(R.color.timeGray));
		} 
		 if(list.get(position).getInselect()==1)
		{
			view.setBackgroundColor(context.getResources().getColor(R.color.timeGreen));
			handle.tv_hsstart.setTextColor(context.getResources().getColor(R.color.white));
//			handle.tv_hsto.setBackgroundResource(R.drawable.img_time_to);
			handle.tv_hsto.setImageResource(R.drawable.img_time_to);
			handle.tv_hsend.setTextColor(context.getResources().getColor(R.color.white));
		}
		 if(list.get(position).getInselect()==2)
		 {
			 view.setBackgroundColor(context.getResources().getColor(R.color.personalBlack)); 
		 }
		return view;
	}

	private class ViewHanlde {
		
		TextView tv_hsstart;
		ImageView tv_hsto;
		TextView tv_hsend;
	}
}
